package com.tff.demo.jdbc;



import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class JdbcDemo {


    public static void main(String[] args) throws Exception {

        //1.注册驱动
       // DriverManager.registerDriver(new Driver());
        Class.forName("com.mysql.jdbc.Driver");


        //2.创建连接
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/spring","root","root");
        //3.创建预定义SQL语句
        PreparedStatement ps = con.prepareStatement("select * from airplane ");
        //4.封装结果集
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            System.out.println(rs.getString(2));
        }
        //5.关闭连接
        rs.close();
        ps.close();
        con.close();
    }
}
